﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <qsplitter.h>
#include "marketselfwidget.h"
#include "marketcomexch.h"
#include "controlwidget.h"
#include "mainorderwidget.h"
#include "popmktcombineexch.h"
#include <QTabWidget>
#include "mainpreentrustwidget.h"
#include "mainconditionwidget.h"
#include "maincombineentrustwidget.h"
#include "mainbalancewidget.h"
#include "mainholdwidget.h"
#include "mainentrustqueryhiswidget.h"
#include "mainbusinessqueryhiswidget.h"
#include "maincontractwidget.h"
#include "mainaverageentrustwidget.h"
#include <QAction>
#include "mainpopdialog.h"
#include "ui_mainpopdialog.h"
#include "selfmarketdialog.h"
#include "ui_selfmarketdialog.h"
#include "popmktcombineexchdialog.h"
#include "ui_popmktcombineexchdialog.h"
#include "combineexchdialog.h"
#include "ui_combineexchdialog.h"
#include "combineorderdialog.h"
#include "ui_combineorderdialog.h"
#include "defaultorderdialog.h"
#include "ui_defaultorderdialog.h"
#include "quickorderdialog.h"
#include "ui_quickorderdialog.h"
#include <QSettings>
#include <QMap>
#include "CommUtil/common.h"
#include "combinecontroldialog.h"
#include<QFile>
#include "UFX/analyStr.h"
#include"ordersetterdlg.h"
#include<QDockWidget>

using namespace std;

namespace Ui {
class MainWindow;
}
//int WINAPI OnReceiveMsg (void* szBuffer, int nType, int iLen);

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    //MainWindow();
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void setupViews();
    void createMenus();
    void createActions();
    void OnUserLogin(QString userid);
    void keyPressEvent ( QKeyEvent * k );
    void closeEvent(QCloseEvent *event);

    void ShowInstrumentMarginRateInfo(IF2UnPacker *lpUnPacker);
	void ShowContractInfo(IF2UnPacker *lpUnPacker);
    void ShowHoldsInfo(IF2UnPacker *lpUnPacker);
    void ShowTradeRecsInfo(IF2UnPacker *lpUnPacker);
    void ShowHisTradeRecsInfo(IF2UnPacker *lpUnPacker);

    void OnDepthMarketData(const char* msg);
    ///报单回报
    void OnRtnOrder(IF2UnPacker *lpUnPacker,QString time);
    void OnRtnOrder(const char* msg);
    ///成交回报
    void OnRtnTrade(const char* msg);
    ///查询资金账户响应
    void OnRspQryTradingAccount(IF2UnPacker *lpUnPacker);
signals:
	void SigRaiseOrderDockWidget();
public slots:
    void SlotdockLocationChanged(int index);
    void SlotdockLocationChanged1(Qt::DockWidgetArea);
    void SlotdockLocationChanged2(Qt::DockWidgetArea);
    void SlotdockLocationChanged3(Qt::DockWidgetArea);
    void SlotdockLocationChanged4(Qt::DockWidgetArea);
    void SlotdockLocationChanged5(Qt::DockWidgetArea);
    void SlotdockLocationChanged6(Qt::DockWidgetArea);
    void SlotdockLocationChanged7(Qt::DockWidgetArea);

    void SlotGetOpenRatio(char bs,QString ordertype,QString futucode,double price);
    ///撤单
    void SlotCancelOrder(const char* exch_type, int entrust_no,int CancelType);
    /// 改单
    void SlotChangeOrder();

    ///平所持持仓
    void SlotClosePositon(QString exch_type,QString contract_code, char c_bs, char c_direction, char c_hedge,int real_enable_amount,int enable_amount);
    void OrderInsert(const char* exch_type, const char* contract_code, char c_bs, char c_direction, char c_hedge, int l_entrust_amount, double en_entrust_price);
    void SlotOrderInsert(FastInfo* pFastInfo);
    void SlotkeyPressEvent ( QKeyEvent * k );
    void OrderSetterDlgShow();
    void MainPopDlgShow();
    void destroyWin();
    void exit();
private:
    OrderSetterDlg* m_pOrderSetterDlg;

	//订阅行情的合约数量和合约列表
	int m_iContractCount;
	char** m_Instrument;
	long							m_lInstrumentCount;

    QSplitter*						mainSplitter,*vSplitter,*hSplitter;
    QTabWidget*						tabWidget,*tabWidget2;
    MarketSelfWidget*				marketselfwidget;
    MarketComexch*					marketcomexch;
    PopMktCombineExch*				popmktcombineexch;
    ControlWidget*					controlwidget;//对应自选行情的控制模块
    CombineControlDialog*           m_CombineControlDlg;//对应自定义组合行情的控制模块
    MainOrderWidget*				mainorderwidget;
    MainPreEntrustWidget*			mainpreentrustwidget;
    MainConditionWidget*			mainconditionwidget;
    MainCombineEntrustWidget*		maincombineentrustwidget;
    MainBalanceWidget*				mainbalancewidget;//资金一览
    MainHoldWidget*					mainholdwidget;//持仓一览
    MainEntrustQueryHisWidget*		mainentrustqueryhiswidget;//未成交单
    MainBusinessQueryHisWidget*		mainbusinessqueryhiswidget;//成交查询
    MainContractWidget*				maincontractwidget;//合约信息
    MainAverageEntrustWidget*		mainaverageentrustwidget;
    QMenu* fileMenu;//文件菜单
    QMenu* editMenu;//编辑菜单
    QMenu* helpMenu;//帮助菜单
    QMenu* formatMenu;

    QAction* m_pOrderSetterAction;
    QAction* newAct,* newAct1,* newAct2,* newAct3,* newAct4,* newAct5,* newAct6;//新建
    QAction* exitAct;//退出

    QAction* aboutAct1;//关于
    QLabel*  infoLabel;
    QDialog* m_MainPopDialog;
    QGridLayout* mainlayout;
    QHBoxLayout* buttonlayout;

    Ui::MainWindow  *ui;
};

#endif // MAINWINDOW_H
